<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <title>管理员列表</title>
    <%--<script src="../js/jquery-3.4.1.js"></script>--%>
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.js"></script>
</head>
<body>
<input type="button" id="btnAdd" value="添加管理员">
<table>
    <thead>
    <tr>
        <td>序号</td>
        <td>管理员账号</td>
        <td>创建时间</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${list}" var="admin">
        <tr>
            <td>${admin.adminID}</td>
            <td>${admin.adminName}</td>
            <td><fmt:formatDate pattern="yyyy年MM月dd日" value="${admin.createTime}"/></td>
                <%--<td><a href="/admin/admin?id=${admin.id}">删除</a></td>--%>
            <td>
                <input type="button" onclick="del(${admin.adminID})" value="删除">
                <input type="button" onclick="edit(${admin.adminID})" value="修改">
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
</body>

<script>
    /**
     * 修改
     * @param id
     */
    function edit(id) {
        window.location.href="/admin/admin?flag=edit&id=" + id;
        // $.get("/admin/admin?flag=edit&id=" + id, function (data, status) {
        //     // if (status == "success") {
        //     //     alert(data);
        //     // }
        //     // window.location.href="http://localhost:8080/admin/admin";
        // })

    }

    /**
     * 删除
     * @param id
     */
    function del(id) {
        if (confirm("是否删除")) {
            $.get("/admin/admin?flag=del&id=" + id, function (data, status) {
                if (status == "success") {
                    alert(data);
                }
                window.location.href = "http://localhost:8080/admin/admin";
            })
        }
    }

    $("#btnAdd").click(function () {
        window.location.href = "AdminForm.jsp";
    })
</script>
</html>

